package utils

import (
	"gopkg.in/yaml.v2"
	"io/ioutil"
	"log"
)

type Yaml struct {
	Server struct {
		Port string `yaml:"port"`
	}
}

var Config *Yaml

// 读取配置
// 参数1: 配置全路径
func ReadYaml(path string) (*Yaml, error) {
	Config = new(Yaml)

	yamlFile, err := ioutil.ReadFile(path)
	if err != nil {
		log.Printf("yamlFile.Get err #%v ", err)
		return nil, err
	}

	err = yaml.Unmarshal(yamlFile, Config)
	if err != nil {
		log.Printf("Unmarshal: %v", err)
		return nil, err
	}

	return Config, nil
}
